package com.srwl.mytx.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.os.Build;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import com.srwl.mytx.R;


/**
 * Created by dahai2070 on 2016/11/9 0009.
 */
public class OfferDialogNew extends Dialog {
    Context context;

    protected final Point p = new Point();

    public OfferDialogNew(Context context) {
        super(context);
        this.context = (Activity) context;

        init();
    }

    protected void init() {

        Window window = getWindow();
        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.setContentView(R.layout.fragment_offer_dialog);
        //  window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        //WindowManager.LayoutParams wlp = window.getAttributes();
        //  wlp.gravity = Gravity.BOTTOM|Gravity.FILL_HORIZONTAL;

     //   wlp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        //`6  wlp.dimAmount = 0f;
       // window.setAttributes(wlp);
       // wlp.screenWidth = screenWidth;
        window.setDimAmount(0f);
       // window.setAttributes(wlp);
        window.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL);
        getSize(window.getWindowManager(), p);
        window.setLayout(p.x, WindowManager.LayoutParams.WRAP_CONTENT);
    }

    public static void getSize(WindowManager wm, Point p) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
            wm.getDefaultDisplay().getSize(p);
        } else {
            p.x = wm.getDefaultDisplay().getWidth();
            p.y = wm.getDefaultDisplay().getHeight();
        }
    }

}
